package it.unipd.dei.bd.icineasti.database;

import it.unipd.dei.bd.icineasti.resource.Tariffa;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Aggiorna una Tariffa data la Fascia
 * 
 * @author Morris Antonello
 */
public class UpdateTariffaBigliettoDatabase {
	/**
	 * Aggiornamento
	 */
	private static final String STATEMENT = "UPDATE Tariffa " +
											"SET PrezzoListino = ?, In3D = ? " +
											"WHERE Fascia = ?";
	
	/**
	 * Connessione al database
	 */
	private final Connection con;
	
	private final Tariffa tariffa;

	public UpdateTariffaBigliettoDatabase(Connection con, Tariffa tariffa) {
		this.con = con;
		this.tariffa = tariffa;
	}

	public void updateTariffa() throws SQLException {

		PreparedStatement pstmt = null;

		try {
			pstmt = con.prepareStatement(STATEMENT);
			pstmt.setBigDecimal(1, tariffa.getPrezzoListino());
			pstmt.setBoolean(2, tariffa.getIn3D());
			pstmt.setString(3, tariffa.getFascia());

			pstmt.executeUpdate();
			
		} finally {
			if (pstmt != null) {
				pstmt.close();
			}
			
			con.close();
		}
	}
}
